package com.lsf.studentmanagerup.servlet.classbean;

import com.lsf.studentmanagerup.bean.ClassBean;
import com.lsf.studentmanagerup.service.ClassBeanService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 李树飞
 */
@WebServlet(name = "AddClassBeanServlet", urlPatterns = "/addClassBean")
public class AddClassBeanServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");

        //获取参数保存到ClassBean对象中
        ClassBean classBean = new ClassBean();
        classBean.setId(Integer.parseInt(request.getParameter("id")));
        classBean.setName(request.getParameter("name"));
        classBean.setGrade(request.getParameter("grade"));
        classBean.setTeacher(request.getParameter("teacher"));
        classBean.setSlogen(request.getParameter("slogen"));
        //班级默认人数0
        classBean.setNum(0);

        //调用服务层新增班级的方法
        ClassBeanService classBeanService = new ClassBeanService();
        classBeanService.addClassBeanService(classBean);

        //重定向班级查询
        response.sendRedirect("getClassBean");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
